﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WeManageService;

namespace WeManageForm
{
    public partial class ListFrom : Form
    {
        public Plan plan = new Plan();

        public ListFrom()
        {
            InitializeComponent();
            LoadData();
			DGVPlan.CellContentClick += PlanDetailBtnClick;
		}

        private void LoadData()
        {
			PlanQueryArgs arg = new PlanQueryArgs();
			arg.MinTime = DateTime.UtcNow;
			arg.MaxTime = arg.MinTime.AddDays(7).AddSeconds(-1);
			arg.QueryTimeType = 1;
            arg.PState = 0;
			BSPlan.DataSource = PlanManager.QueryPlan(arg);
        }
		
		private void PlanDetailBtnClick(object sender, DataGridViewCellEventArgs e)
		{
			if (DGVPlan.Columns[e.ColumnIndex].Name == "DetailBtn")
			{
				if (e.RowIndex == -1) return;
				foreach (DataGridViewCell cell in DGVPlan.Rows[e.RowIndex].Cells)
				{
					if (cell.OwningColumn.DataPropertyName == "PlanID")
					{
						Plan plan = PlanManager.GetPlanClone((int)cell.Value);
						PlanForm form = new PlanForm(1, plan);
						form.Closed += (_1, _2) => LoadData();
						form.Show();
					}
				}
			}
		}
	}
}
